package group.igfd.manager.biz.controller;

import com.alibaba.fastjson.JSON;
import group.igfd.manager.biz.service.PublishBuyersService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;

@RestController
@Api(tags = {"A100 / 买手统计接口"})
@RequestMapping("biz/buyerStatistics")
public class BuyerStatisticsController {
    private Logger logger = LoggerFactory.getLogger(BuyerStatisticsController.class);

    @Autowired
    private PublishBuyersService publishBuyersService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation("获取买手统计信息")
//    @RequiresPermissions("biz:buyerStatistics:bonus")
    public R list(@RequestParam Map<String, Object> params){
        logger.info("biz:buyerStatistics:list===params[{}]", JSON.toJSONString(params));
        PageUtils pageUtils = publishBuyersService.queryStatistics(params);
        logger.info("biz:buyerStatistics:list's response [{}]", JSON.toJSONString(pageUtils));
        return R.ok().put("page", pageUtils);
    }

    @RequestMapping(value = "/export", method = RequestMethod.GET)
    @ApiOperation("导出")
    public void export(String uid, String dt, HttpServletResponse response) throws IOException {
        logger.info("export====uid: [{}], dt:[{}]", uid, dt);
        publishBuyersService.export(uid, dt, response);

    }
}
